<!--
	作者：956911785@qq.com
	时间：2019年5月16日14:27:09
	描述：学生-导入
-->

<template>
	<Modal title="导入摇号成功的学生" v-model="modal0" width="500px">
		<Form :label-width="100" label-position="right">
			<div style="width:100%;height:150px; overflow-y:hidden;">
		        
		         <div style="width:100%;float:left;text-align: center;">
			         <div style="width:50%;float:left;">
				        <FormItem  label="文件上传">
						    <Upload :action="action" 
						    	:format="['xls','xlsx']" 
						    	:on-format-error="handleFormatError"
						    	:show-upload-list="true" ref="upload" 
						    	:disabled="uploadDisable"
						    	:on-remove="removeFile"
						    	:on-success="success" >
					        	<Button icon="ios-cloud-upload-outline">请选择文件</Button>
					    	</Upload>
		        		</FormItem>
			        </div>
			        <div style="width:50%;float:left;text-align: center;">
					    <Button icon="md-cloud-download" @click="downModel">模板下载</Button>
			        </div>
		        </div>
		        
		   </div> 
	    </Form>
	   	<div slot="footer">
	    	<Button type="text"  @click="closeModal()">取消</Button>
	    	<Button type="primary" @click="addsave()" >确定</Button>
	    </div>
     </Modal>
</template>

<script>
	const _config = require('./../../../../../config/config')
	export default {
		name:"addteacher",
		props: {
    	},
		data() {
			return {
                modal0:false,
                params:{
                	filename:'',
					filepath:''
                },
                files:{},
                action:_config._ADMIN_SERVER+"/bmxt/filesUpload.html",
                uploadDisable:false,
			}
		},
		components: {
		},
		methods: {
            closeModal(){
	      	    this.modal0 = false;
	        },
	        success(e){
				const files={
					filename:e[0].DISK_FILE_NAME,
					filepath:e[0].FILE_PATH
				}
				this.files=files;
				this.uploadDisable=true;
	        },
	        handleFormatError (file) {
                this.$Notice.warning({
                    title: '文件上传失败',
                    desc: '文件' + file.name + '无法上传, 上传文件请选择xls or xlsx.'
                });
            },
            removeFile(file){
            	this.$refs.upload.clearFiles();
            	this.uploadDisable=false;
            },
            addsave(){
            	const params={
            		filename:this.files.filename,
            		filepath:this.files.filepath
            	}
            	//保存
				this.$http.post("/host/bmxt/student/import_Student.html",params)
				.then(result => {
					if(result){
						this.$Modal.success({
                            title: "成功",
                            content: "导入成功！",
                            onOk: () => {
                            	this.modal0 = false;
					    		this.$emit("reload");
                            }
                       });
					}else{
						this.$Modal.error({
                            title: "失败",
                            content: "导入失败！"
                        });	
					}
				});
           },
           
           downModel(){
           		window.open(_config._ADMIN_SERVER+"/bmxt/downloadfile.html?fileurl=static/importstudent.xls")
           }
		},
		mounted() {
		
  			
		},
		watch:{
			modal0(news,olds){
				this.files="";
				this.files.filename="";
				this.files.filepath="";
			}
		},
		computed: {
			
		}
		
	}
</script>

<style scoped="scoped">
	
</style>



